<html>
<head><meta charset="utf-8"><title>Check if an enum is tuple or struct like · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html">Check if an enum is tuple or struct like</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="243952152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243952152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243952152">(Jun 25 2021 at 18:21)</a>:</h4>
<p>Is the only way to tell if an enum definition is struct or tuple like by checking the HIR for the item? I looked through <code>AdtDef</code>, <code>TyKind</code> and the methods on <code>TyCtxt</code> but couldn't find anything that seemed relevant.</p>



<a name="243952295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243952295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243952295">(Jun 25 2021 at 18:22)</a>:</h4>
<p>I need to avoid using HIR because I want to determine this information for enums defined in upstream crates.</p>



<a name="243961992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243961992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243961992">(Jun 25 2021 at 19:46)</a>:</h4>
<p>I'm pretty convinced there isn't a way to do this right now. I wonder if this would be generally useful for user facing things like error messages. (cc <span class="user-mention" data-user-id="119031">@Esteban Küber</span>) </p>
<p>What I'd like to do is detect when an enum is tuple like so I can apply the tuple type naming scheme we use on msvc so that it will visualize correctly in Windows debuggers instead of simply showing <code>__0</code>, <code>__1</code> etc for field names. I would guess there are some error messages that might like to know if the enum fields are tuple or struct like as well.</p>



<a name="243962180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962180">(Jun 25 2021 at 19:48)</a>:</h4>
<p>There are ways but they aren't great</p>



<a name="243962191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962191">(Jun 25 2021 at 19:48)</a>:</h4>
<p>Oh interesting ...</p>



<a name="243962204"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962204" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962204">(Jun 25 2021 at 19:48)</a>:</h4>
<p>Of the top of my head you can check the field names</p>



<a name="243962217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962217">(Jun 25 2021 at 19:48)</a>:</h4>
<p>If they are integers</p>



<a name="243962227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962227">(Jun 25 2021 at 19:48)</a>:</h4>
<p>Ah</p>



<a name="243962234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962234">(Jun 25 2021 at 19:48)</a>:</h4>
<p>I ruled that out.</p>



<a name="243962235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962235">(Jun 25 2021 at 19:48)</a>:</h4>
<p>But check what we do when misusing the patterns</p>



<a name="243962287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Check%20if%20an%20enum%20is%20tuple%20or%20struct%20like/near/243962287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Check.20if.20an.20enum.20is.20tuple.20or.20struct.20like.html#243962287">(Jun 25 2021 at 19:49)</a>:</h4>
<p>At dentist right now, ping me in an his</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>